
class BASE_DATATYPE (dict):

  SCHEMA = None

  def __init__(self, *args, **kwargs):
    dict.__init__(self, *args, **kwargs)
    self.__dict__ = self

  @classmethod
  def GetSchema(cls):
    return cls.SCHEMA

class META_RECORD(BASE_DATATYPE):
  """
    {
      type: datetime, date, time, str, int, float, bool, dict
      required: True|False
      min:
      max:
      regex: <str>
      collection_type: list, set, dict
      collection_min:
      collection_max:
    }
  """

class EmailTemplate(BASE_DATATYPE):
  """
  {
    'key': <str>,
    'description': <str>,
    'to': { <str>1..* },
    'cc': { <str>0..* },
    'subject': <str>,
    'body': <str>
  }
  """
  SCHEMA = {
    'key': META_RECORD({
      'type': 'str',
      'required': True,
      'min': 1,
      'max': 16,
      'regex': '^[-A-Za-z0-9\.]+$',
    }),
    'description': META_RECORD({
      'type': 'str',
      'required': True,
      'min': 0,
      'max': 1024,
    }),
    'to': META_RECORD({
      'type': 'set',
      'required': True,
      'min': 1,
      'regex': '^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$',
    }),
    'cc': META_RECORD({
      'type': 'set',
      'required': True,
      'regex': '^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$',
    }),
    'subject': META_RECORD({
      'type': 'str',
      'required': True,
      'min': 1,
      'max': 1024,
    }),
    'body': META_RECORD({
      'type': 'str',
      'required': True,
      'min': 1,
    })
  }


class EmailTemplateAbstract(BASE_DATATYPE):
  """
  {
    'key': <str>,
    'description': <str>
  }
  """



class ResolutionFailure(BASE_DATATYPE):
  """
  {
    'type': <str>
    'msg': <str>
    'detail': <str>
  }
  """
